package org.goj.management.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.goj.common.entity.management.Mail;
import org.goj.management.mapper.MailMapper;
import org.goj.management.service.MailService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.goj.management.vo.AdminMailVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 消息列表 服务实现类
 * </p>
 *
 * @author CK
 * @since 2021-04-23
 */
@Service
public class MailServiceImpl extends ServiceImpl<MailMapper, Mail> implements MailService {

    @Resource
    private MailMapper mailMapper;

    @Override
    public Boolean adminAddMail(Integer contestId, Integer adminUserId, String title, String content) {
        Mail mail = new Mail();
        mail.setContestId(contestId).setAdminUserId(adminUserId).setTitle(title)
                .setContent(content).setInDate(new Date()).setDefunct("N").setType(0);
        return super.save(mail);
    }

    @Override
    public List<AdminMailVO> adminMailList(Integer contestId) {
        QueryWrapper<Mail> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("contest_id", contestId)
                .orderByDesc("type")
                .orderByDesc("in_date");
        return mailMapper.adminMailList(queryWrapper);
    }

    @Override
    public Boolean addMail(Integer contestId, Integer ordUserId, String title, String content) {
        Mail mail = new Mail();
        mail.setContestId(contestId).setOrdUserId(ordUserId).setTitle(title)
                .setContent(content).setInDate(new Date()).setDefunct("N").setType(2);
        return super.save(mail);
    }
}
